import java.awt.Color;
import java.awt.Graphics;
import java.util.Arrays;

public class Character {
//		Frame f = new Frame();
        private int cnum;
        private int cframe;
        private int palette;
        private Color[][] palettes = {{new Color(0,0,0,0),new Color(248,248,248),new Color(182,164,222),new Color(24,24,24)}};
        ROM rom = new ROM();
       /** private int[] cpos = f.getpos();
        private boolean cstep = f.getstep();
        private int[] cmove = f.getmove();
        private int[] cmap = f.getmap();
        private int[] cblock = f.getblock();
        private boolean[] cblocked = f.getblocked();
        private int cmapsize = f.getmapsize();
        private boolean[] cpress = f.getpress();*/
//      private int[][] graphic = {
//                      {0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,
//                       0,0,0,0,3,2,2,2,2,2,2,3,0,0,0,0,
//                       0,0,0,3,2,2,2,2,2,2,2,2,3,0,0,0,
//                       0,0,0,3,2,2,2,2,2,2,2,2,3,0,0,0,
//                       0,0,3,3,3,2,1,1,1,1,2,3,3,3,0,0,
//                       0,0,3,3,1,3,3,3,3,3,3,1,3,3,0,0,
//                       0,3,1,3,1,1,1,1,1,1,1,1,3,1,3,0,
//                       0,3,1,1,1,1,3,1,1,3,1,1,1,1,3,0,
//                       0,0,3,3,1,1,3,1,1,3,1,1,3,3,0,0,
//                       0,0,3,3,3,1,1,2,2,1,1,3,3,3,0,0,
//                       0,3,1,1,3,3,3,3,3,3,3,3,1,1,3,0,
//                       0,3,1,1,3,3,3,3,3,3,3,3,1,1,3,0,
//                       0,0,3,3,3,2,2,3,3,2,2,3,3,3,0,0,
//                       0,0,0,3,2,3,3,2,2,3,3,2,3,0,0,0,
//                       0,0,0,3,2,2,2,3,3,2,2,2,3,0,0,0,
//                       0,0,0,0,3,3,3,0,0,3,3,3,0,0,0,0,}
//                      
//                      };
//        
//        private int[][] graphic = {
//        {0x003FFC00,0x00EAAB00,0x03AAAAC0,0x03AAAAC0,0x0FE55BF0,0x0F7FFDF0,0x375555DC,0x355D755C,
//         0x0F5D75F0,0x0FD697F0,0x35FFFF5C,0x35FFFF5C,0x0FEBEBF0,0x03BEBEC0,0x03ABEAC0,0x00FC3F00}
//        };
        
        private int[][] graphic = {
        		rom.getBytes(0x0C06C0+0x00 /* +0x40, +0x80, +0x100 ... */, 0x180)
        };

        
        public Character(int pCnum, int pCframe, int pPalette){
                this.cnum=pCnum;
                this.cframe=pCframe;
                this.palette=pPalette;
        }
        
        public void draw8x8Tile(Graphics g, int x, int y, int offset, boolean mirror){
            for (int i=0;i<64;i++){
            	g.setColor(palettes[this.palette][
            	                                  ((((graphic[this.cnum][i/8+i/8+offset])>>(7-(i%8)))&0x1))+
            	                                  ((((graphic[this.cnum][i/8+i/8+1+offset])>>(7-(i%8)))&0x1)<<1)
            	                                		  ]);
            	if (mirror){
            		g.drawLine(x+7-(i%8), y+(i/8), x+7-(i%8), y+(i/8));
            	}else{
            		g.drawLine(x+(i%8), y+(i/8), x+(i%8), y+(i/8));
            	}
            }
        }
        
        public void drawCharacter(Graphics g, int x, int y){
                Color temp = g.getColor();
                if ((this.cframe/6)==1){
                    this.cframe%=6;
	                draw8x8Tile(g,x+8,y,0 + this.cframe*0x40,true);
	                draw8x8Tile(g,x,y,0x10 + this.cframe*0x40,true);
	                draw8x8Tile(g,x+8,y+8,0x20 + this.cframe*0x40,true);
	                draw8x8Tile(g,x,y+8,0x30 + this.cframe*0x40,true);
                }else{
                    this.cframe%=6;
	                draw8x8Tile(g,x,y,0 + this.cframe*0x40,false);
	                draw8x8Tile(g,x+8,y,0x10 + this.cframe*0x40,false);
	                draw8x8Tile(g,x,y+8,0x20 + this.cframe*0x40,false);
	                draw8x8Tile(g,x+8,y+8,0x30 + this.cframe*0x40,false);
                }
                g.setColor(temp);
        }
        
        public void setCframe(int pCframe){
        	this.cframe=pCframe;
        }
        
       /** public void moving(){
        	if((cpos[0]%16==0) && (cpos[1]%16==0)){
        		f.setstep(false);
        		f.setmove(0,0);
        		f.setmove(1,0);
        		for (int i = 0; i < 4; i++){
        			if (cmap[cpos[0]]/16 + cblock[i*2] + (cpos[1]/16 + cblock[i*2+1]) * cmapsize != 0){
        				f.setblocked(i, true);
        			}
        			else{
        				f.setblocked(i, false);
        			}
        		}
        	}
        	f.label1.setText("");
        	for (int i = 0; i < 4; i++){
        		if(cstep != cpress[i]){
        			if(cblocked[i]){
        				f.label1.setText("Boom!");
        			}
        			else{
        				f.setstep(true);
        				f.setmove(i/2,((int) Math.pow(-1, i)));
        			}
        		}
        	}
        }
        
        public void updatepos(){
        	for(int i = 0; i < 2; i++){
        		f.setpos(i, (cpos[i]+cmove[i]));
        	}
        }*/
}
